package org.linlinjava.litemall.db.service;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.db.dao.PiccNurseMapper;
import org.linlinjava.litemall.db.domain.PiccNurse;
import org.linlinjava.litemall.db.domain.PiccNurseExample;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class PiccNurseService {
    private final Log logger = LogFactory.getLog(PiccNurseService.class);
    @Resource
    private PiccNurseMapper piccNurseMapper;

    /**
     * 返回所有的护士list信息
     * @param page
     * @param limit
     * @param sort
     * @param order
     * @return
     */
    public List<PiccNurse> getNurseList(Integer page, Integer limit, String sort, String order){
        PiccNurseExample piccNurseExample = new PiccNurseExample();

        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order)) {
            piccNurseExample.setOrderByClause(sort + " " + order);
        }

//        PageHelper.startPage(page, limit);
        return piccNurseMapper.selectByExample(piccNurseExample);
    }

    /**
     * 返回护士详情，根据id
     * @param id
     * @return
     */
    public PiccNurse getDetailById(Integer id){
        return piccNurseMapper.selectByPrimaryKey(id);
    }

    /**
     * 返回护士详情，根据userid
     * @param userId
     * @return
     */
    public PiccNurse getDetailByUserId(Integer userId){
        PiccNurseExample piccNurseExample = new PiccNurseExample();
        PiccNurseExample.Criteria criteria = piccNurseExample.createCriteria();
        criteria.andUserIdEqualTo(userId);
        return piccNurseMapper.selectOneByExample(piccNurseExample);
    }

    /**
     * 返回护士详情，根据工号
     * @param jobNum
     * @return
     */
    public PiccNurse getDetailByJobNum(String jobNum){
        PiccNurseExample piccNurseExample = new PiccNurseExample();
        PiccNurseExample.Criteria criteria = piccNurseExample.createCriteria();
        criteria.andJobNumberEqualTo(jobNum);
        return piccNurseMapper.selectOneByExample(piccNurseExample);
    }



    /**
     *  添加新的护士信息
     * @param record
     * @return
     */
    public PiccNurse add(PiccNurse record){
        record.setAddTime(LocalDateTime.now());
        logger.debug("ljf---> "+record);
        piccNurseMapper.insertSelective(record);
        return record;
    }

    /**
     * 更新护士信息，根据护士id
     * @param record
     * @param record
     * @return
     */
    public PiccNurse update(PiccNurse record){
        piccNurseMapper.updateByPrimaryKey(record);
        return record;
    }
}
